package com.mvvm.start.main.mvvm.vm

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.*
import com.mvvm.start.base.base.BaseViewModel
import com.mvvm.start.main.bean.result.Repo
import com.mvvm.start.main.mvvm.m.PagingRepository
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch

/**
 * @功能: paging3分页可库
 * @User Lmy
 * @Creat 2021/11/1 10:36 上午
 * @Compony 永远相信美好的事情即将发生
 */
class PagingViewModle : BaseViewModel() {
    val sharedFlow = MutableSharedFlow<String>(1)

    fun test() {
        viewModelScope.launch {
            sharedFlow.emit("Hello")
            sharedFlow.emit("SharedFlow")
        }
    }

    fun getPagingData(): LiveData<PagingData<Repo>> {
        return PagingRepository.getPagingData().cachedIn(viewModelScope)
    }
}



